package com.example.demo.bean;

import com.example.demo.bean.group.UserUpdate;
import com.example.demo.bean.jacksonserialize.ToLowerCaseCaseSerializer;
import com.example.demo.bean.jacksonserialize.ToUpperCaseSerializer;
import com.example.demo.annotation.CheckDate;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.*;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.Date;

/**
 * Created by lyc on 2019/5/31.
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class User {

    private Integer id;

    @NotBlank(message = "名字不能为空")
    private String name;

    @NotNull(message = "年龄不能为空")
    private Integer age;

    @NotNull(message ="手机号码不能为空")
    private String pthone;

    @NotBlank(message = "邮箱不能我空",groups = {UserUpdate.class})
    @JsonSerialize(using = ToUpperCaseSerializer.class)
    @JsonDeserialize(using = ToLowerCaseCaseSerializer.class)
    private String email;

    @CheckDate(message = "时间日期格式化错误")
    @DateTimeFormat(pattern = "yyyy-MM-dd") //入参 spring 注解 格式化时间
    private Date date;
}
